#! /bin/sh

name=libgcc
from_source=gcc-host
clean_workdirs=no
skip_pkg_check=yes
revision=1
hostdeps="gcc pkg-config"
imagedeps="experimental:build-essential"
deps="mlibc"

build() {
    cd "${base_dir}"/host-builds/gcc/build

    make -j${parallelism} all-target-libgcc
}

package() {
    cd "${base_dir}"/host-builds/gcc/build

    rm -rf tmp_libgcc_dir
    mkdir tmp_libgcc_dir

    DESTDIR="$(realpath tmp_libgcc_dir)" make install-target-libgcc

    mkdir -p "${dest_dir}${prefix}"

    cp -r tmp_libgcc_dir/usr/local/lib "${dest_dir}${prefix}"/
    cp -r tmp_libgcc_dir/usr/local/${OS_TRIPLET}/* "${dest_dir}${prefix}"/

    # Copy libgcc into GCC's tree else it will complain.
    mkdir -p "${base_dir}"/host-pkgs/gcc/usr/local/lib
    cp -r tmp_libgcc_dir/usr/local/lib/* "${base_dir}"/host-pkgs/gcc/usr/local/lib/
}
